//
//  ICLcblayoutButton.m
//  ICome
//
//  Created by Administrator on 2017/4/12.
//  Copyright © 2017年 iCom. All rights reserved.
//

#import "ICLcblayoutButton.h"
#import "ICHeaderFile.h"


@implementation ICLcblayoutButton

-(void)setLcbType:(LCBRelayoutButtonType)lcbType
{
    _lcbType = lcbType;
    if(lcbType != LCBRelayoutButtonTypeNomal)
    {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
}

//重写父类方法,改变标题和image的坐标
- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    
    CGRect rect;
    switch (self.lcbType) {
        case LCBRelayoutButtonTypeNomal:
        {
            return [super imageRectForContentRect:contentRect];
        }break;
        case LCBRelayoutButtonTypeLeft:
        {
            CGFloat x = contentRect.size.width  - self.imageSize.width - self.offset;
            CGFloat y =  contentRect.size.height -  self.imageSize.height;
            y = y/2;
            rect = CGRectMake(x,y,self.imageSize.width,self.imageSize.height);
        }break;
        case LCBRelayoutButtonTypeRight:
        {
            CGFloat x =  self.offset;
            CGFloat y =  contentRect.size.height -  self.imageSize.height;
            y = y/2;
            rect = CGRectMake(x,y,self.imageSize.width,self.imageSize.height);
            
        }break;
        case LCBRelayoutButtonTypeTop:
        {
            CGFloat x =  contentRect.size.width -  self.imageSize.width;
            
            CGFloat y =  contentRect.size.height - self.imageSize.height - self.offset;
            
            x = x / 2;
            
            rect = CGRectMake(x,y,self.imageSize.width,self.imageSize.height);
            
        }break;
        case LCBRelayoutButtonTypeBottom:
        {
            CGFloat x =  contentRect.size.width -  self.imageSize.width;
            
            CGFloat y =  self.offset ;
            
            x = x / 2;
            
            rect = CGRectMake(x,y + App_Frame_Width/375.0f * (14.5),self.imageSize.width,self.imageSize.height);
            
        }break;
        case LCBRelayoutButtonTypeNo:
        {
            rect = CGRectMake(0.0, 0.0, contentRect.size.width, contentRect.size.height);
            
        }break;
        case LCBRelayoutButtonTypeYse:
        {
            rect = CGRectMake(0.0, 0.0, 0, 0);
        }break;
        case LCBRelayoutButtonTypeNoFill:
        {
            CGFloat x =  contentRect.size.width -  self.imageSize.width;
            CGFloat y =  contentRect.size.height - self.imageSize.height;
            x = x/2;
            y = y/2 - self.offset;
            rect = CGRectMake(x,y, self.imageSize.width, self.imageSize.height);
        }break;
            
        default:
        {
            return [super imageRectForContentRect:contentRect];
        }break;
    }
    
    return rect;
    
    
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    
    CGRect rect;
    switch (self.lcbType) {
        case LCBRelayoutButtonTypeNomal:
        {
            return [super titleRectForContentRect:contentRect];
        }break;
        case LCBRelayoutButtonTypeLeft:
        {
            rect = CGRectMake(0, 5, contentRect.size.width - self.imageSize.width - self.offset - self.titleoffset, contentRect.size.height-10);
        }break;
        case LCBRelayoutButtonTypeRight:
        {
            rect = CGRectMake(self.imageSize.width+self.offset+self.titleoffset, 0, contentRect.size.width - self.imageSize.width - self.offset - self.titleoffset, contentRect.size.height);
        }break;
        case LCBRelayoutButtonTypeTop:
        {
            
            rect = CGRectMake(0,0,  contentRect.size.width  , contentRect.size.height  - self.imageSize.height- self.offset - self.titleoffset);
        }break;
        case LCBRelayoutButtonTypeBottom:
        {
            rect = CGRectMake(App_Frame_Width/375.0f * (5),  self.titleoffset + self.offset + self.imageSize.height+App_Frame_Width/375.0f * (18) , contentRect.size.width-App_Frame_Width/375.0f * (10) , contentRect.size.height - self.imageSize.height - self.offset - self.titleoffset-App_Frame_Width/375.0f * (29.5));
        }break;
        case LCBRelayoutButtonTypeNo:
        {
            rect = CGRectMake(0.0, 0.0, 0, 0);
            
        }break;
        case LCBRelayoutButtonTypeYse:
        {
            rect = CGRectMake(0.0, 0.0, contentRect.size.width, contentRect.size.height);
        }break;
        case LCBRelayoutButtonTypeNoFill:
        {
            rect = CGRectMake(0.0, 0.0, 0, 0);
        }break;
            
        default:
        {
            return [super titleRectForContentRect:contentRect];
        }break;
    }
    
    return rect;
    
    
}

@end
